//
//  GRPersonalCertificationViewController.m
//  YC_GRice
//
//  Created by LiuFeng on 2018/7/23.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRPersonalCertificationViewController.h"
#import "GRCertificationHeader.h"
#import "GRCertificationFooter.h"
#import "GRCertificationViewCell.h"

@interface GRPersonalCertificationViewController ()

{
    NSArray *titleArray;
    NSArray *keys;
}

@property (nonatomic, strong) NSDictionary *resultDic;

@end

@implementation GRPersonalCertificationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    titleArray = @[@"真实姓名", @"身份证号", @"银行卡号", @"银行名称", @"手机号"];
    keys       = @[@"name", @"idCardNumber", @"bankNumber", @"bankName", @"mobile"];
    // Uncomment the following line to preserve selection between presentations.
    GRCertificationHeader *header  = [[GRCertificationHeader alloc] initWithCertification:GRCertificationPersonal];
    self.tableView.tableHeaderView = header;
    
    GRCertificationFooter *footer  = [[GRCertificationFooter alloc] initWithFrame:CGRectMake(0, 0, KscreenWidth, 65)];
    [footer.sureBtn setTitle:@"已认证" forState:UIControlStateNormal];
    self.tableView.tableFooterView = footer;
    self.tableView.backgroundColor = KGMBACKGROUND_COLOR;
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    [self.tableView registerNib:[UINib nibWithNibName:@"GRCertificationViewCell" bundle:nil] forCellReuseIdentifier:@"GRCertificationViewCell"];
    
    [self getCertificationInfomation];
}

- (void)getCertificationInfomation {
    [GRCertificationAction getPersonalCertificationInfomation:^(BOOL success, id responseObject, GRError *error) {
        if (success) {
            self.resultDic = responseObject;
            [self.tableView reloadData];
        }else {
            [GRHUD showMessage:[error errorMsg] atView:self.view];
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return titleArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    GRCertificationViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GRCertificationViewCell" forIndexPath:indexPath];
    cell.titleLabel.text = titleArray[indexPath.row];
    if (cell.infoTextField.enabled) {
        cell.infoTextField.enabled = NO;
    }
    NSString *key           = keys[indexPath.row];
    cell.infoTextField.text = self.resultDic[key];
    return cell;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
